﻿<!DOCTYPE html>
<html>
<head>
    <title>更新栏目</title>
</head>
<body>

        <div id="area" class="area" style="overflow-y:auto;">
  
                <div class="form" id="form1">
                    <input type="hidden" field="pi" value="${pi}" />
                    <input type="hidden" field="si" value="${si}" />

                        <div class="title" style="margin-top: 0">
                            <span class="icon icon1"></span>修改菜单</div>

                        <div class="fl">
                            <div class="label"><span class="red">*</span>名称：</div>
                            <div class="in">
                                <input type="text" class="tb_normal ui-validate" required="true" length="[0,50]" summary="{required:'不能为空!',length:'长度不能超过50位!'}" field="name" id="name" />
                                <div class="tip">5字以内</div>
                            </div>
                        </div>


                        <div class="fl">
                            <div class="label"><span class="red">*</span>类型：</div>
                            <div class="in">
                                <input type="radio" class="radio" field="type" name="type" id="type1" value="click" checked="checked" /><label for="type1">按钮</label>
                                <input type="radio" class="radio" field="type" name="type" id="type2" value="view" /><label for="type2">链接</label>
                            </div>
                        </div>

                        <div class="fl hidden" id="fl_link">
                            <div class="label"><span class="red">*</span>链接：</div>
                            <div class="in">
                                <input type="text" field="url" style="width: 300px" />
                                <div class="note">
                                    1. 请填写完整的链接，如http://www.abc.com/weixin/<br/>
                                    2. 本站域名使用{local}代替<br/>
                                    3. 如需授权使用{auth}代替，如{auth}http://www.abc.com
                                </div>
                            </div>
                        </div>

                        <div class="fl" id="fl_click">
                            <div class="label"><span class="red">*</span>资源：</div>
                            <div class="in">
                                <input type="text" field="key" value="res:" />
                                <div class="note">
                                    可以用"res:素材名称"调用素材
                                </div>
                            </div>
                        </div>
                        <div class="fl" id="fl_click">
                            <div class="label"></div>
                            <div class="in">
                                <a id="btn" class="btn" href="javascript:;">保存</a>
                            </div>
                        </div>

        </div>

    </div>

    <script type="text/javascript">
        var entity = ${entity} ||{};
        cms.json.bind('form1',entity);


        //设置是否跳转显示
        var flLink = cms.$('fl_link');
        var flClick = cms.$('fl_click');


        function chkType(e){
            if(!e)e=this;
            if(e.checked && e.value == 'click'){
                flLink.className = 'fl hidden';
                flClick.className='fl';
            }else{
                flLink.className = 'fl';
                flClick.className='fl hidden';
            }
        }

        cms.$('type1').onchange = cms.$('type2').onchange =chkType;
        chkType(cms.$('type1'));



        window.saveData = function () {
            if (cms.validator.validate()) {
                var data=cms.json.toObject('form1');
                cms.xhr.jsonPost(
                     'editmenu',
                     data,
                     function (json) {
                         if (json.result) {
                             parent.M.alert(json.message);
                             setTimeout(function() { location.reload(); }, 2000);
                         } else {
                             parent.M.alert(json.message);
                         }
                     });
            }
        };

        cms.$('btn').onclick = window.saveData;
        cms.validator.init('form1');
    </script>
</body>
</html>
